package org.zwd.computePrice.action;

import java.util.List;

import org.zwd.computePrice.domain.Crab;
import org.zwd.computePrice.domain.Temp;
import org.zwd.computePrice.service.CrabService;
import org.zwd.computePrice.service.TempService;
import org.zwd.computePrice.util.DateUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CrabAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private CrabService crabService = new CrabService();
	private TempService tempService = new TempService();
	
	private int id;
	private int isOrder;
	
	public String list() throws Exception{
		List<Crab> crabList = null;
		String date = null;
		String name = null; 
		String title = null;
		if(id !=0){
			Temp temp = tempService.findTempByTempid(id,isOrder);
			date = temp.getDate();
			crabList = temp.getCrabList();
			name = temp.getClientName();
			tempService.deleteItemByid(id);
		}else{
			date = DateUtils.getToday();
			crabList = crabService.findAllCrab(isOrder);
		}
		ActionContext.getContext().put("date",date);
		ActionContext.getContext().put("crabList", crabList);
		ActionContext.getContext().put("name", name);
		List<Temp> tempList = tempService.LoadAllTemp(isOrder);
		ActionContext.getContext().put("tempList", tempList);
		if(isOrder == 0){
			title = "出货清单";
		}else{
			title = "收货清单";
		}
		ActionContext.getContext().put("title", title);
		ActionContext.getContext().put("isOrder", isOrder);
		return "list";
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getIsOrder() {
		return isOrder;
	}

	public void setIsOrder(int isOrder) {
		this.isOrder = isOrder;
	}
	
	
}
